<template>
  <el-config-provider :locale="currentLocale">
    <router-view />
    <ReDialog />
  </el-config-provider>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { ElConfigProvider } from 'element-plus';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import { ReDialog } from '@/components/ReDialog';
import { useUserStoreHook } from '@/store/modules/user';
import { getTopMenu, initRouter } from '@/router/utils';
import { message } from '@/utils/message';

export default defineComponent({
  name: 'app',
  components: {
    [ElConfigProvider.name]: ElConfigProvider,
    ReDialog
  },
  computed: {
    currentLocale() {
      return zhCn;
    }
  },
  created() {
    useUserStoreHook()
      .loginByUsername({ username: 'admin', password: 'admin123' })
      .then(res => {
        if (res.success) {
          // 获取后端路由
          initRouter().then(() => {
            this.$router.push(getTopMenu(true).path);
            message('登录成功', { type: 'success' });
          });
        }
      });
  }
});
</script>
